// (c)2016 Flipboard Inc, All Rights Reserved.

package com.ysalliance.getFan.organization.network;


import com.ysalliance.getFan.organization.network.api.UtilApi;

import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
import retrofit2.CallAdapter;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.ysalliance.getFan.organization.FanerConstant.MyBaseUrl;


public class Network {

    private static UtilApi utilApi;  //是否需要环信服务


    private static OkHttpClient okHttpClient =
            new Builder()
//                    .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC))
                    .addInterceptor(new LogInterceptor())
//                    .proxy(Proxy.NO_PROXY)     //防代理抓包
                    .build();


    //    private static OkHttpClient okHttpClient = new OkHttpClient();
    private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
    private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();


    public static UtilApi getUtilApi() {
        if (utilApi == null) {
            Retrofit retrofit = new Retrofit.Builder()
                    .client(okHttpClient)
                    .baseUrl(MyBaseUrl)
//                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(rxJavaCallAdapterFactory)
                    .build();
            utilApi = retrofit.create(UtilApi.class);
        }
        return utilApi;
    }


}
